﻿using System;
using System.Collections.Generic;
using System.Linq;

class MaximumSubarraySum
{
    static void Main()
    {
        int result = int.MinValue;
        int sum = 0;
        int start = 0;

        Console.Write("Number of elements of array:");
        int arrayLength = int.Parse(Console.ReadLine());
        List<int> array = new List<int>();
        for (int i = 0; i < arrayLength; i++)
        {
            Console.Write("\nInt element a[{0}]:", i);
            array.Add(int.Parse(Console.ReadLine()));
        }

        //int[] tempList = { 2, 3, -6, -1, 2, -1, 6, 4, -8, 8 };

        List<int> ListOfNumbers = new List<int>();

        int startIndex = 0;
        int endIndex = 0;        

        for (int index = 0; index < array.Count; index++)
        {
            sum += array[index];
            ListOfNumbers.Add(array[index]);
            if (sum > result)
            {
                result = sum;
                startIndex = start;
                endIndex = index;
            }
            if (sum < 0)
            {
                ListOfNumbers.Clear();
                sum = 0;
                start = index + 1;
            }
        }
        Console.Write("The biggest subarray is: {0}",ListOfNumbers[0]);

        for (int i = 1; i < ListOfNumbers.Count; i++)
			{
			 Console.Write(", "+ListOfNumbers[i]);
			}

        Console.Write(" = {0}",result);
        Console.WriteLine();
    }
}